import requests
import re
s = requests.Session()
proxies = {
    "http": "http://127.0.0.1:8888",
    "https": "http://127.0.0.1:8888",
}
certFile = "./.zhengshu.crt"

url1 = "https://user.360kad.com/Login/AjaxLoginV2"
bodyDL = {'userName': '18222338776', 'pass': 'wzz123456', 'isRemberName': 'false', 'loginPlatform': '1'}
r = s.post(url1, data=bodyDL)
print(r.text)



url2 = "https://user.360kad.com/Integral/GetDayIntegral?_=1604932241058"
r1 = s.get(url2)
print(r1.text)
print("1111111111111111111111")

for i in range(1001, 1101):
    url3 = f"https://www.360kad.com/Favorite/AddFavorite?wareCode={i}&rd=0.9592793058187621"#插入变量时需要格式化
    # print("url3:", url3)
    r2 = s.get(url3)
print("r2: ", r2.text)

#for i in range(1,30):
#先从我的收藏页面获取一个商品ID，然后子啊获取所有的商品ID   常见的签名使用MD5对字段进行加密，加密之后再传过去（相当于加个字段），
url4 = "https://user.360kad.com/favorite"#收藏接口
r3 = s.get(url4)
print("r3get: ", r3)
#print(r3.text)
#正则表达式提取一个ID
reg="val\('(.*?)'\);confirmPop"#"val\('(.*?)');confirmPop)"
allid = re.findall(reg, r3.text)#在字符串中找到正则表达式所匹配的所有子串，并返回一个列表，如果没有找到匹配的，则返回空列表。语法格式为：findall(string[, pos[, endpos]])
print("allid: ", allid)
print("[0]:", allid[0])
#取消收藏(取消1个商品）取消所有的要加循环
url5 ="https://user.360kad.com/Favorite/Delete?Id="+allid[0]
r4 = s.post(url5, verify=certFile)
print("r4: ", r4)
print("r4post: ", r4.text)